package com.wn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.common.PageParam;
import com.wn.mapper.RoomMapper;
import com.wn.ov.HospitalizedApplicationOv;
import com.wn.ov.RoomOv;
import com.wn.pojo.Room;
import com.wn.resopnse.ResponseCode;
import com.wn.resopnse.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: his
 * @BelongsPackage: com.wn.service.nurseService
 * @Author: 皓芷
 * @CreateTime: 2020-10-23 17:18
 * @Description: 床位业务处理
 */
@Service
public class RoomService {

    @Autowired
    private RoomMapper roomMapper;

    public ServerResponse getRoomList(PageParam<RoomOv> pageParam){
        //分页
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        //排序
        for(int i=0;i<pageParam.getOrderParams().length;i++){
            PageHelper.orderBy(pageParam.getOrderParams()[i]);
        }

        //获取床位列表
        List<RoomOv> roomList = roomMapper.getRoomList(pageParam.getModel());
        PageInfo<RoomOv> roomPageInfo = new PageInfo<RoomOv>(roomList);
        return new ServerResponse(ResponseCode.SUCCESS,roomPageInfo);
    }

    //根据病房id获取科室id
    public Integer getDepartmentId(Integer id){
        return roomMapper.getDepIdByBedId(id);
    }

    //修改床位使用情况
    public Integer updateIsUsedByRoomId(Room room){
        return roomMapper.updateByPrimaryKeySelective(room);

    }

    //获取病房列表（不分页）
    public List<RoomOv> getRoomListByBox(RoomOv roomOv){
        return roomMapper.getRoomList(roomOv);
    }

}
